package com.jx.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jx.dao.FindFuncByDidDao;
import com.jx.model.Func;
import com.jx.util.JDBCUtil;

public class FindFuncByDidDaoimpl implements FindFuncByDidDao {
	/**
	 * 根据did查询它的功能
	 * @param did
	 * @return
	 */
	@Override
	public List<Func> findFuncByDid(int did) {
		// TODO Auto-generated method stub
		List<Func> funcs=new ArrayList<Func>();
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("select j_func.* from j_func,dep_func,j_dep where j_dep.did=dep_func.did AND j_func.fid=dep_func.fid AND j_dep.did=?");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setInt(1, did);
			ResultSet res=pst.executeQuery();
			while(res.next()){
				Func funcid=new Func(res.getInt("fid"),res.getString("fname"));
				funcs.add(funcid);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return funcs;
	}
}